package com.example.library.model;

import com.example.library.enums.ResultCode;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2024-12-20
 * Time: 23:32
 */
@Data
public class Result {
    private ResultCode code;//0 成功, -1 失败. -2 未登录 表示后端是否正常相应
    private String errMsg;//错误信息
    private Object data;
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }
    public static Result fail(String m) {
        Result result = new Result();
        result.setCode(ResultCode.FAIL);
        result.setData(null);
        result.setErrMsg(m);
        return result;
    }
    public static Result unlogin() {
        Result result = new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
